﻿#region Header
//************************************************************************************
// Name: FileIO
// Description: FileIO
// Created On:  02-Aug-2011
// Created By:  Swathi
// Last Modified On:
// Last Modified By:
// Last Modified Reason:
//*************************************************************************************
#endregion Header
using System.IO;

namespace Base.Utils
{
    public sealed class FileIO
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="strDirectoryname"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static bool CheckDirectory(string strDirectoryname)
        {
            if (!Directory.Exists(strDirectoryname))
            {
                Directory.CreateDirectory(strDirectoryname);
            }
            return true;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="fileNameWithFullPath"></param>
        /// <returns></returns>
        public static bool CreateFile(string fileNameWithFullPath)
        {
            try
            {
                string folder = Path.GetDirectoryName(fileNameWithFullPath);
                CheckDirectory(folder);
                if (!File.Exists(fileNameWithFullPath))
                {
                    File.Create(fileNameWithFullPath);
                    return true;
                }
                return false;
            }
            catch
            {
                return false;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="fileNameWithFullPath"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        public static void WriteFile(string fileNameWithFullPath, string content)
        {
                var fs = new FileStream(fileNameWithFullPath, FileMode.Append, FileAccess.Write);
                var sw = new StreamWriter(fs);
                sw.WriteLine(content);
                sw.Close();
                fs.Close();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        public static string GetFileName(string filePath)
        {
            string fileName = Path.GetFileName(filePath);
            return fileName;
        }

        /// <summary> 
        /// 
        /// </summary> 
        /// <param name="filePath"></param> 
        /// <returns></returns> 
        public static bool IsFileExists(string filePath)
        {
            return (File.Exists(filePath)) ? true : false;
        }

        public static void DeleteFile(string filePath)
        {
            File.Delete(filePath);
        }
    }
}